{% extends "djforum/base.html" %}

{% load i18n staticfiles forum_tags %}

{% block content %}
    <div class="pull-right topic-toolbar">
        <a href="{% url 'main:search' %}" class="btn btn-small">{% trans "Search" %}</a>

        {% if user.is_authenticated %}
            {% with unread_count=user|unread_topics_count %}
            <a href="{% url 'forum:unread_topics' %}" class="btn btn-small">
                {% trans "Unread topics" %}{% if unread_count %} ({{ unread_count }}){% endif %}
            </a>
            {% endwith %}
            <a href="{% url 'forum:my_topics' %}" class="btn btn-small">{% trans "My topics" %}</a>
            <a href="{% url 'forum:mark_read_all' %}" class="btn btn-small">{% trans "Mark all as read" %}</a>
        {% endif %}

        <a href="{% url 'forum:feed_latest_entries' %}" class="btn btn-small">{% trans "RSS" %}</a>
    </div>

    {% for category in categories %}
    <aside class="widget forum">
        <h5 class="short_headline"><span>{{ category }}</span></h5>

        {% with forums=category.forums.all %}
        {% if forums %}
        <table class="table table-bordered table-condensed">
            <thead>
                <tr>
                    <th></th>
                    <th class="number-column center smaller hidden-phone">{% trans "Topics" %}</th>
                    <th class="number-column center smaller hidden-phone">{% trans "Posts" %}</th>
                    <th class="last-post center">{% trans "Last post" %}</th>
                </tr>
            </thead>
            <tbody>
            {% for forum in forums %}
                <tr {% if forum|has_unread:user %}class="success"{% endif %}>
                    <td class="topic-name">
                        <a href="{{ forum.get_absolute_url }}" class="forum-title">{{ forum }}</a>
                        {% if forum.description %}
                        <p class="description">{{ forum.description }}</p>
                        {% endif %}
                    </td>
                    <td class="smaller center hidden-phone">{{ forum.topics_count }}</td>
                    <td class="smaller center hidden-phone">{{ forum.posts_count }}</td>
                    <td class="smaller last-post">
                        {% with last_post=forum.last_post %}
                        {% if last_post %}
                            <a href="{{ last_post.get_absolute_url }}">
                                <i class="fa fa-clock-o"></i> {{ last_post.created|date:'DATETIME_FORMAT' }}
                            </a><br>
                            <a href="{{ last_post.get_absolute_url }}"><i class="fa fa-pencil"></i> {{ last_post.user|softwraphtml }}</a>
                        {% endif %}
                        {% endwith %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        {% endif %}
        {% endwith %}
        {% if forloop.counter == 1 or forloop.last %}{% include "_yandex.html" with index=forloop.counter %}{% endif %}
    </aside>
    {% endfor %}

    <div class="row-fluid">
        <div class="span4">
            {% trans "Total number of registered users:" %} {{ users_count }}<br>
            {% trans "Total number of topics:" %} {{ topics_count }}<br>
            {% trans "Total number of posts:" %} {{ posts_count }}
        </div>
        <div class="span8">
            {% trans "Registered users online:" %} {{ online_count }}<br>
            {% trans "Guests online:" %} {{ guest_count }}
            {% if online_count %}
                <br><strong>{% trans "Online:" %} </strong>
                {% for online in users_online %}
                    <a href="{{ online.get_absolute_url }}">{{ online }}</a>
                {% endfor %}
            {% endif %}
        </div>
    </div>
{% endblock %}
